package com.example.a2205douyin.live;

import android.content.Context;
import android.os.Handler;
import android.view.View;

import com.example.a2205douyin.entity.GiftEntity;

import java.util.Timer;
import java.util.TimerTask;

public class BaoCon {
    private BaoLayout baoLayout;
    Timer timer;
    Handler handler = new Handler(){};
    long lastTime;
    int count;

    public BaoCon(BaoLayout baoLayout) {
        this.baoLayout = baoLayout;
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
               if(System.currentTimeMillis()-lastTime>5000){
                   //刷新UI
                   handler.post(new Runnable() {
                       @Override
                       public void run() {
                           baoLayout.setVisibility(View.GONE);
                           count = 0;
                       }
                   });
               }
            }
        },0,100);
    }
    public void load(GiftEntity.DataBean dataBean){
        //发送时先显示
        if(count==0){
            baoLayout.setVisibility(View.VISIBLE);
            count++;
            lastTime = System.currentTimeMillis();
        }else if(System.currentTimeMillis()-lastTime<2000){
            count++;
            lastTime = System.currentTimeMillis();
        }
        baoLayout.load(dataBean.getGiftpath(),count);
    }
}
